// 层序遍历
function levelOrder(root) {
    let result = []
    // 用队列
    let queue = []
    if (root) {
        queue.push(root)
    }
    while (queue.length) {
        let level = []
        let len = queue.length
        for (let i = 0; i < len; i++) {
            let node = queue.shift()
            level.push(node.val)
            if (node.left) {
                queue.push(node.left)
            }
            if (node.right) {
                queue.push(node.right)
            }
        }
        result.push(level)
    }
    return result
}

const root = {
    val: "A",
    left: {
        val: "B",
        left: {
            val: "D",
        },
        right: {
            val: "E",
        },
    },
    right: {
        val: "C",
        right: {
            val: "F",
        },
    },
};

console.log(levelOrder(root))